package br.com.vendaext.teste;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class BusinessProfiler {

//	@Pointcut("execution(* br.com.vendaext.teste.*.*(..))")
//	public void businessMethods() {	}
//
//	@Around("businessMethods()")
//	public Object profile(ProceedingJoinPoint pjp) throws Throwable {
//		long start = System.currentTimeMillis();
//		System.out.println("Going to call the method.");
//		Object output = pjp.proceed();
//		System.out.println("Method execution completed.");
//		long elapsedTime = System.currentTimeMillis() - start;
//		System.out.println("Method execution time: " + elapsedTime + " milliseconds.");
//		return output;
//	}
	@AfterThrowing(pointcut="execution(* br.com.vendaext.teste.*.*(..))", throwing="e")
	public void tratarExcecao(Exception e) {
//		FacesContext context = FacesContext.getCurrentInstance();
//		context.addMessage(null, new FacesMessage(e.getMessage()));
		e.printStackTrace(); 
	}

}
